package hk.m4s.lr.repair.test.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import hk.m4s.lr.repair.test.R;
import hk.m4s.lr.repair.test.model.TableModle;

/**
 * Created by za-hetong on 2017/2/7.
 */

public class HorizontalListViewAdapters extends BaseAdapter {

    public List<TableModle> list=new ArrayList<>();
    Context context;
    LayoutInflater inflater;
    public int flag=-1;
    public HorizontalListViewAdapters(Context context, List<TableModle> data){
        this.context=context;
        this.list=data;
        inflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if(convertView==null){
            holder=new ViewHolder();
            convertView=inflater.inflate(R.layout.item_tab_layout_custom,parent,false);
            holder.day_text=(TextView)convertView.findViewById(R.id.tabName);
            holder.tabImag=(ImageView) convertView.findViewById(R.id.tabImage);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        holder.day_text.setText(list.get(position).getName());
        holder.tabImag.setImageResource(list.get(position).getImages());
        return convertView;
    }

    public static class ViewHolder{
        TextView day_text;
        ImageView tabImag;
    }
}
